<template>
    <el-form ref="form" :model="user.userInfo" :rules="rules" label-width="170px">
        <el-form-item label="学历" prop="educatiod">
            <el-select v-model="user.userInfo.educatiod" placeholder="请选择学历" style="width: 250px;" clearable>
                <el-option v-for="item in dict.type.basic_educatiod_dict" :key="parseInt(item.value)" :label="item.label" :value="parseInt(item.value)"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="学位" prop="degree">
            <el-select v-model="user.userInfo.degree" placeholder="请选择学位" style="width: 250px;" clearable>
                <el-option v-for="item in dict.type.basic_degree_dict" :key="parseInt(item.value)" :label="item.label" :value="parseInt(item.value)"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="学位类型" prop="degreeType">
            <el-select v-model="user.userInfo.degreeType" placeholder="请选择学位类型" style="width: 250px;" clearable>
                <el-option v-for="item in dict.type.basic_degree_type_dict" :key="parseInt(item.value)" :label="item.label" :value="parseInt(item.value)"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="授权最高学位院校及专业" prop="highestDegree">
            <el-input v-model="user.userInfo.highestDegree" maxlength="50" style="width: 250px;" clearable/>
        </el-form-item>
        <el-form-item>
            <el-button type="danger" size="mini" @click="close" plain>关闭</el-button>
            <el-button type="primary" size="mini" @click="submit" plain>保存</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
import {updateUserProfile} from "@/api/system/user";

export default {
    props: {
        user: {
            type: Object,
        }
    },
    dicts: ['basic_educatiod_dict', 'basic_degree_dict', 'basic_degree_type_dict'],
    data() {
        return {
            // 表单校验
            rules: {
                educatiod: [
                    {required: true, message: "请选择学历", trigger: "blur"}
                ],
                degree: [
                    {required: true, message: "请选择学位", trigger: "blur"}
                ],
                degreeType: [
                    {required: true, message: "请选择学位类型", trigger: "blur"}
                ]
            }
        };
    },
    methods: {
        submit() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    let body = {
                        userId: this.user.userId, userInfo: this.user.userInfo
                    }
                    updateUserProfile(body).then(response => {
                        this.$modal.msgSuccess("修改成功");
                    });
                }
            });
        },
        close() {
            this.$tab.closePage();
        }
    }
};
</script>
